package org.softmed.action.states.custom;

import org.softmed.action.ActionStep;
import org.softmed.action.exception.StopException;
import org.softmed.action.interfaces.SelfExceptionSolver;
import org.softmed.action.states.State;

public class NormalState extends State {

	public NormalState(String name) {
		super(name);
	}

	@Override
	public void execute() throws Throwable {
		if (stateChangeListener != null)
			stateChangeListener.stateChanged(this);

		exception = null;

		for (ActionStep action : actionSteps) {

			try {
				action.execute();
			} catch (Throwable tef) {
				failedAction = action;
				exception = tef;
				if (action instanceof SelfExceptionSolver)
					((SelfExceptionSolver) action)
							.resolveMyOwnException(exception);

				// if (!(tef instanceof StopException))
				goFailure();

				throw exception;
			}
		}

		goSuccess();
	}

}
